package cn.jtfadmin.core.modules.sys.domain.entity;


import cn.jtfadmin.base.data.jpa.domain.entity.BaseEntity;
import cn.jtfadmin.base.lang.common.domain.entity.NamedTreeEntity;
import cn.jtfadmin.base.lang.enums.BooleanEnum;
import cn.jtfadmin.core.enums.MenuTypeEnum;
import cn.jtfadmin.core.enums.OperateTypeEnum;
import lombok.Getter;
import lombok.Setter;
import org.springframework.util.comparator.Comparators;

import javax.persistence.*;
import javax.validation.constraints.NotNull;

/**
 * 菜单权限表
 */
@Getter
@Setter
@Table(name = "sys_permission")
@Entity
public class SysPermissionEntity extends BaseEntity implements NamedTreeEntity, Comparable<SysPermissionEntity> {


    /**
     * 菜单/权限名称
     */
    @Basic
    @Column(name = "name", nullable = false)
    protected String name;


    /**
     * 菜单图标，菜单时有效
     */
    @Basic
    @Column(name = "icon")
    protected String icon;

    /**
     * 组件，菜单时有效
     */
    @Basic
    @Column(name = "component")
    protected String component;


    /**
     * 操作权限编码，例如：“sys:schedule:list,sys:schedule:info”,多个逗号隔开， 权限有效
     */
    @Basic
    @Column(name = "perms")
    protected String perms;

    /**
     * 路径，菜单路径or操作权限url
     */
    @Basic
    @Column(name = "url")
    protected String url;
    /**
     * 一级菜单跳转地址，菜单时有效
     */
    @Basic
    @Column(name = "redirect")
    protected String redirect;

    /**
     * 排序，
     */
    @Basic
    @Column(name = "sort_no")
    protected Integer sortNo;

    /**
     * 类型， 菜单权限
     */
    @Basic
    @Column(name = "menu_type")
    @Enumerated(EnumType.STRING)
    protected MenuTypeEnum menuType;


    /**
     * 描述
     */
    @Basic
    @Column(name = "description")
    protected String description;


    /**
     * 是否隐藏路由菜单: 0否,1是（默认值0） ，菜单时有效
     */
    @Basic
    @Column(name = "hidden")
    @Enumerated(EnumType.STRING)
    protected BooleanEnum hidden;

    /**
     * 菜单时有效，是否是路由菜单
     */
    @Basic
    @Column(name = "route_flag")
    @Enumerated(EnumType.STRING)
    protected BooleanEnum routeFlag;


    /**
     * 菜单时有效
     */
    @Basic
    @Column(name = "keep_alive")
    @Enumerated(EnumType.STRING)
    protected BooleanEnum keepAlive;

    /**
     * 操作类型,权限时有效
     */
    @Basic
    @Column(name = "operate_type")
    @Enumerated(EnumType.STRING)
    protected OperateTypeEnum operateType;


    /**
     * 父id
     */
    @Column(name = "parent_id")
    protected String parentId;

    /**
     * 所有的父IDS
     */
    @Column(name = "parent_ids")
    protected String parentIds;


    @Override
    public int compareTo(@NotNull SysPermissionEntity o) {
        return Comparators.nullsHigh().compare(this.sortNo, o.sortNo);
    }
}
